package com.htc.callcare.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.util.Log;

import com.htc.callcare.infrastructure.globalVar;

public class recordModel implements Comparable<recordModel>{
	// true-income
	// flase-out_ome
	// 1-income call
	// 0-out going call
	// 1-check
	// 0-not check
	public int id;
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int callType;
	public String callTime;
	public String callDay;
	public String callNumber;
	public String note;
	public int isCheck;
	public String fileUri;
	public int separator;
	public Date date;
	//1 is important;
	//0 is not important;
	public int important;
	
	
	public int getImportant() {
		return important;
	}

	public void setImportant(int important) {
		this.important = important;
	}

	public static final String dateFormat = "yyyy-MM-dd HH:mm";
	public int getSeparator() {
		return separator;
	}

	public void setSeparator(int separator) {
		this.separator = separator;
	}

	public recordModel(String callDay, int separator) {
		super();
		this.separator = separator;
		this.callDay = callDay;
	}

	public recordModel(String fileUri) {
		super();
		this.fileUri = fileUri;
		String raw = "";
		
		try {
			
			String[] temp = removeExtension(fileUri, raw).split("_");
			if (temp[0].equals(globalVar.incoming)) {
				this.callType = 1;
			} else {
				this.callType = 0;
			}
			this.callTime = temp[1].replace("h", ":");
			this.callDay = temp[2];
			this.callNumber = temp[3];
			this.separator = 0;
			this.important = 0;
			

		} catch (Exception e) {
			// TODO: handle exception
			this.callTime = "00:00";
			this.callDay = "2000-1-1";
			this.callNumber = "0909090909";
			this.separator = 0;
			removeExtension(fileUri, raw);
			this.important = 0;
		}
		this.date = new Date(Integer.parseInt(this.callDay.split("-")[0]), Integer.parseInt(this.callDay.split("-")[1]), Integer.parseInt(this.callDay.split("-")[2]),
				Integer.parseInt(this.callTime.split(":")[0]), Integer.parseInt(this.callTime.split(":")[1]));
	}

	public String removeExtension(String fileUri, String raw) {
		if (fileUri.endsWith(globalVar.amrType)) {
			raw = fileUri.replace(globalVar.amrType, "");
		} else if (fileUri.endsWith(globalVar.mp4Type)) {
			raw = fileUri.replace(globalVar.mp4Type, "");
		} else if (fileUri.endsWith(globalVar.three_gppType)) {
			raw = fileUri.replace(globalVar.three_gppType, "");
		}
		return raw;
	}

	public int getCallType() {
		return callType;
	}

	public void setCallType(int callType) {
		this.callType = callType;
	}

	public String getCallTime() {
		return callTime;
	}

	public void setCallTime(String callTime) {
		this.callTime = callTime;
	}

	public String getCallDay() {
		return callDay;
	}

	public void setCallDay(String callDay) {
		this.callDay = callDay;
	}

	public String getCallNumber() {
		return callNumber;
	}

	public void setCallNumber(String callNumber) {
		this.callNumber = callNumber;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public int getIsCheck() {
		return isCheck;
	}

	public void setIsCheck(int isCheck) {
		this.isCheck = isCheck;
	}

	public String getFileUri() {
		return fileUri;
	}

	public void setFileUri(String fileUri) {
		this.fileUri = fileUri;
	}

	@Override
	public int compareTo(recordModel another) {
	/*	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");*/
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
/*		Date date1 = null;
		Date date2 = null;
		if (another != null) {
			try {
				date1 = sdf.parse(callDay + " " + callTime.split("h")[0] + ":"
						+ callTime.split("h")[1]);
				Log.v("thuutai", ""+another.callDay + " "
						+ another.callTime.split("h")[0] + ":"
						+ another.callTime.split("h")[1]);
				Log.v("reocordModel", ""+another.callDay+"     "+another.callTime);
				
				date2 = sdf.parse(another.callDay + " "
						+ another.callTime.split("h")[0] + ":"
						+ another.callTime.split("h")[1]);
			} catch (ParseException e) {
				e.printStackTrace();

			}
		}*/
		int reuslt = 0;
		try{
			reuslt = date.compareTo(another.date);
		}
		catch (NullPointerException e) {
			// TODO: handle exception
		}
		if (reuslt > 0) {
			return -1;
		}
		if (reuslt < 0) {
			return -0;
		} else {
			return 0;
		}

	}
	
}
